<template>
  <zz-dialog
    title='文件上传'
    @close="close"
    confirmVal='提交'
    :showConfirm = 'file_allow'
    @confirm="submit_file"
    :visible=visible>
    <div v-if="file_allow">
      <div style="width: 600px;">
        <div class="add_table">
          <div class="add_left">{{fileData.name}}</div>
          <div class="add_right">
            <input type="file" @change="changeFile($event)" ref="_file">
          </div>
        </div>
      </div>

      <div class="tableClass mt10" style="width: 700px;">
        <table style="table-layout: fixed" width="700" height="200">
          <tr>
            <th>模板</th>
            <td>
              <a :href="doc_downLoadLink"><button class="button-line">点击下载</button></a>
            </td>
          </tr>
          <tr style="width: 700px;">
            <th>接口说明</th>
            <td style="height: 200px;width: 700px;" >
              <p style="word-wrap:break-word;">
                {{doc_description.url}}
              </p>
            </td>
          </tr>
        </table>
      </div>
    </div>
    <div v-if="!file_allow" >
        子系统未授权
    </div>
  </zz-dialog>
</template>

<script>

  import webuploader from '../../commom/webuploader'

  export default {
    name: "edit_Upload",
    data() {
      return {
        fileList: [],
        url:'',
        formData: {
          id: ''
        },
        doc_description: '',
        doc_downLoadLink:'',
        file_allow:false,
        par1:'',
        fileData:''
      }
    },
    components: {
      webuploader: webuploader
    },
    props: {
      visible: {
        type: Boolean,
        default: false
      },
      fileData: {
        type: Object,
        default: {}
      }
    },
    methods: {
      close() {
        this.$emit('close')
      },
      // 接口上传信息

      changeFile(e){
        this.fileData = e.target.files
        console.log(e.target.files);
      },

      get_uploadDataInfo(par1, par2) {
        //alert(1)

        this.par1 = par1

        this.url = `${this.$site.videoServer}/interface/interface_upload`+ par1 +`.do`

        this.$axios({
          method: 'get',
          url: `${this.$site.videoServer}/interface/interface_upload` + par1 + `/` + par2 + `.do`
        }).then(res => {
          console.log(res);
          if (res.data.status == 200) {
            this.file_allow = true
            this.doc_description = res.data.data
            this.doc_downLoadLink = `${this.$site.videoServer}/` + res.data.data.template
          }else{
            this.file_allow = false
          }
        })
      },
      submit_file () {

        const form = new window.FormData()
        form.append('file', this.$refs._file.files[0])

        this.$axios.post(`${this.$site.videoServer}/interface/interface_upload`+ this.par1 +`.do`, form).then(res=>{
          if(res.data.status == 200){
            this.$message.success('上传成功')
            this.close()
          }else{
            this.$message.error(res.data.msg)
          }
        })

      }
    }
  }
</script>

<style scoped lang="scss">
  .tableClass {
    tr {
      td {

      }
    }
  }
</style>
